package com.erpservertwo.service.impl;

import com.erpservertwo.entity.Menu;
import com.erpservertwo.entity.MenuData;
import com.erpservertwo.entity.MenuData2;
import com.erpservertwo.mapper.MenuMapper;
import com.erpservertwo.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    private List<Menu> menus;

    @Override
    public List<MenuData> select(Long uuid) {
//        List<MenuData> menuDataList= menuMapper.select(uuid);
//        return menuDataList;


            //        List<MenuDate>装所有数据
//        List<MenuDate> list = new ArrayList<>();
            List<MenuData> list = new ArrayList<>();

            //查询一级标题
            List<Menu> menus = menuMapper.selectOneTitle(uuid);
            for (Menu menu : menus) {
                MenuData menuDate = new MenuData();
                menuDate.setMenuId(menu.getMenuId());
                menuDate.setPid(menu.getPid());
                menuDate.setName(menu.getMenuName());
                menuDate.setTitle(menu.getMenuName());
                menuDate.setIcon(menu.getIcon());
                menuDate.setSpread(true);

                //查询2级标题
                List<Menu> menusTwo = menuMapper.selectTwoTitle(menu.getMenuId());

                List< MenuData2> list1 = new ArrayList<>();
                for (Menu menu2 : menusTwo) {
                    MenuData2 menuDateTwo = new MenuData2();
                    menuDateTwo.setMenuId(menu2.getMenuId());
                    menuDateTwo.setPid(menu2.getPid());
                    menuDateTwo.setName(menu2.getMenuName());
                    menuDateTwo.setTitle(menu2.getMenuName());
                    menuDateTwo.setJump(menu2.getUrl());
                    list1.add(menuDateTwo);
                }
                menuDate.setList(list1);
//            menuDate.setList(menusTwo);

                list.add(menuDate);
            }

            return list;



        }
}
